#ifndef UDPSOCKET_H
#define UDPSOCKET_H

#include <QObject>
#include <QUdpSocket>
#include <QAbstractSocket>

class udpsocket : public QUdpSocket
{
    Q_OBJECT

    //Q_PROPERTY(QString portName READ portName WRITE setPortName)

    //Q_PROPERTY(ShareAddress shareAddress READ shareAddress)

public:
    explicit udpsocket(QObject *parent = 0);

    Q_INVOKABLE bool socketBind(quint16 port);
    Q_INVOKABLE qint64 socketWrite(const QByteArray & datagram, quint16 port);
    Q_INVOKABLE bool hasPending();
    Q_INVOKABLE QString socketRead();

signals:
    void messageReceive(const QByteArray &msg);
    void messageReceiveInt(const int &msg);

private slots:
    void processPendingDatagrams();

private:
    QByteArray receiveData;


    void dealReceiveData(const QByteArray &ba);
};

#endif // UDPSOCKET_H
